<?php
	@include('include/common.inc.php');	
	@include('logincleck.php');	
	if($_SESSION['type']==1)
	{		
		echo '<script language="javascript">';   		
		echo "window.location.href('member.php');";
		echo '</script>';
	}
    if ($_POST['add']==1)
	{
		
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
		
		include($conf["base_path"] ."class/thumbnail.php");
		
		for($i=1;$i<=30;$i++)
		{
			$furniturex ="furniture".$i;
			$furniturex2 = $_POST[$furniturex];
			if($furniturex2!='')
			{
				if($furniture=='')
				{
					$furniture = $furniturex2;
				}else{
					$furniture = $furniturex2.' / '.$furniture;
				}
			}
			$wiringx ="wiring".$i;
			$wiringx2 = $_POST[$wiringx];
			if($wiringx2!='')
			{
				if($wiring=='')
				{
					$wiring = $wiringx2;
				}else{
					$wiring=$wiringx2.' / '.$wiring;
				}
			}
			$baohangx ="baohang".$i;
			$baohangx2 = $_POST[$baohangx];
			if($baohangx2!='')
			{
				if($baohang=='')
				{
					$baohang = $baohangx2;
				}else{
					$baohang=$baohangx2.' / '.$baohang;
				}
			}
			$firex ="fire".$i;
			$firex2 = $_POST[$firex];
			if($firex2!='')
			{
				if($fire=='')
				{
					$fire = $firex2;
				}else{
					$fire=$firex2.' / '.$fire;
				}
			}
			$baoquanx ="baoquan".$i;
			$baoquanx2 = $_POST[$baoquanx];
			if($baoquanx2!='')
			{
				if($baoquan=='')
				{
					$baoquan = $baoquanx2;
				}else{
					$baoquan=$baoquanx2.' / '.$baoquan;
				}
			}
		}

		$time=date('Y-m-d H:i:s');
		$cate_id = work_str($_POST["city"], 1);

		$query1 = "SELECT * FROM $TBL_HOU_CATE WHERE cate_id=$cate_id";
		$result1 = mysql_query($query1) or die(mysql_error());
		$row1 = mysql_fetch_array($result1);
		$zh_cate_title1 = $row1['zh_cate_title'];
		$parent_id = $row1['parent_id'];
		$query2 = "SELECT * FROM $TBL_HOU_CATE WHERE cate_id=$parent_id";
		$result2 = mysql_query($query2) or die(mysql_error());
		$row2 = mysql_fetch_array($result2);
		$zh_cate_title2 = $row2['zh_cate_title'];
		$cate_name = $zh_cate_title2.$zh_cate_title1;


		$floor = work_str($_POST["Floor1"], 1).'/'.work_str($_POST["Floor2"], 1);				
		$purpose = work_str($_POST["Purpose"], 1);	
		$title = work_str($_POST["title"], 1);	
		$map = work_str($_POST["map"], 1);	
		$address =work_str($_POST["address"], 1); 
		$source = work_str($_POST["source"], 1);	//	
		$typex = work_str($_POST["type"], 1);	//		
		$area = work_str($_POST["area"], 1);			
		$linkman = work_str($_POST["linkman"], 1);		
		$price = work_str($_POST["price"], 1);			
		$sale = work_str($_POST["sale"], 1);			
		$min_sale = work_str($_POST["min_sale"], 1);		
		$deposit = work_str($_POST["deposit"], 1);		
		$layout = work_str($_POST["Room"], 1).'房'.work_str($_POST["LivingRoom"],1).'廳'.work_str($_POST["BathRoom"], 1).'衛'.work_str($_POST["CRoom"], 1).'廚';	
		//$wiring = work_str($_POST["wiring"], 1);		
		//$furniture = work_str($_POST["furniture"], 1);		
		$store = work_str($_POST["store"], 1);		
		$unit = work_str($_POST["unit"], 1);		
		$position = work_str($_POST["position"], 1);		
		$age = work_str($_POST["age"], 1);	
		$tel = work_str($_POST["tel"], 1);	
		$email = work_str($_POST["email"], 1);
		$mobile = work_str($_POST["mobile"], 1);
		$sex = work_str($_POST["sex"], 1);		
		$elevator = work_str($_POST["elevator"], 1);		
		$tese = work_str($_POST["tese"], 1);  //特色
		$hou_name = work_str($_POST["hou_name"], 1);  //大樓案名
	
		$birth =work_str($_POST["Y"],1).'-'.work_str($_POST["M"],1).'-'.work_str($_POST["D"], 1);

		$sel = "select * from $TBL_HOUSE order by num desc";
		$result = mysql_query($sel);
		$row = mysql_fetch_array($result);
		if($row['num']!='')
		{
			$num = $row['num']+1;
		}else{
			$num = 10000;
		}		

		$user_id = $_SESSION['mem_id'];
		$img = $_FILES['img']['name'];	
		$imgname = explode('.',$img);	
		$count = count($imgname)-1;
		$imgn = time().'.'.$imgname[$count];
		$imgn_1 = time().'_1.'.$imgname[$count];

		$query = "INSERT INTO $TBL_HOUSE SET cate_id='$cate_id',add_time='$time',user_id='$user_id',
		num='$num',address='$address',source='$source',type='$typex',area='$area',linkman='$linkman',
		price='$price',sale='$sale',min_sale='$min_sale',deposit='$deposit',layout='$layout',
		floor='$floor',wiring='$wiring',furniture='$furniture',fire='$fire',elevator='$elevator',		unit='$unit',position='$position',age='$age',tel='$tel',img='$imgn_1',hou_type=2,purpose='$purpose',email='$email',birth='$birth',sex='$sex',mobile='$mobile',map='$map',cate_name='$cate_name',title='$title',baohang='$baohang',baoquan='$baoquan',tese='$tese',hou_name='$hou_name',store='$store' ";
		$res = mysql_query($query) or die(mysql_error());
		$insert_id = mysql_insert_id();	
		if($_FILES['img']['name']!='')
		{		
			@mkdir($conf['fck_upload'] . "house/".$insert_id);
			@chmod($conf['fck_upload'] . "house/".$insert_id,0777);	
			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$imgn;
			$upload_file = $_FILES['img']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$imgn;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$imgn_1;		
			new resizeimage($oldpic, "196", "154", "0",$newpic);//缩略图		
		}

		if($_FILES['img1']['name']!='')
		{
			$img1 = $_FILES['img1']['name'];	
			$imgname1 = explode('.',$img1);	
			$count1 = count($imgname1)-1;
			$img1 = '1_'.time().'.'.$imgname1[$count1];
			$img1_1 ='1_'.time().'_1.'.$imgname1[$count1];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img1;
			$upload_file = $_FILES['img1']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img1;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img1_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img1='$img1_1' where id=$insert_id");
		}

		if($_FILES['img2']['name']!='')
		{
			$img2 = $_FILES['img2']['name'];	
			$imgname2 = explode('.',$img2);	
			$count2 = count($imgname2)-1;
			$img2 = '2_'.time().'.'.$imgname2[$count2];
			$img2_1 ='2_'.time().'_1.'.$imgname2[$count2];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img2;
			$upload_file = $_FILES['img2']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img2;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img2_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img2='$img2_1' where id=$insert_id");
		}

		if($_FILES['img3']['name']!='')
		{
			$img3 = $_FILES['img3']['name'];	
			$imgname3 = explode('.',$img3);	
			$count3 = count($imgname3)-1;
			$img3 = '3_'.time().'.'.$imgname3[$count3];
			$img3_1 ='3_'.time().'_1.'.$imgname3[$count3];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img3;
			$upload_file = $_FILES['img3']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img3;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img3_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img3='$img3_1' where id=$insert_id");
		}	

		if($_FILES['img4']['name']!='')
		{
			$img4 = $_FILES['img4']['name'];	
			$imgname4 = explode('.',$img4);	
			$count4 = count($imgname4)-1;
			$img4 = '4_'.time().'.'.$imgname4[$count4];
			$img4_1 ='4_'.time().'_1.'.$imgname4[$count4];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img4;
			$upload_file = $_FILES['img4']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img4;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img4_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img4='$img4_1' where id=$insert_id");
		}

		if($_FILES['img5']['name']!='')
		{
			$img5 = $_FILES['img5']['name'];	
			$imgname5 = explode('.',$img5);	
			$count5 = count($imgname5)-1;
			$img5 = '5_'.time().'.'.$imgname5[$count5];
			$img5_1 ='5_'.time().'_1.'.$imgname5[$count5];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img5;
			$upload_file = $_FILES['img5']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img5;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img5_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img5='$img5_1' where id=$insert_id");
		}

		if($_FILES['img6']['name']!='')
		{
			$img6 = $_FILES['img6']['name'];	
			$imgname6 = explode('.',$img6);	
			$count6 = count($imgname6)-1;
			$img6 = '6_'.time().'.'.$imgname6[$count6];
			$img6_1 ='6_'.time().'_1.'.$imgname6[$count6];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img6;
			$upload_file = $_FILES['img6']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img6;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img6_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img6='$img6_1' where id=$insert_id");
		}

		if($_FILES['img7']['name']!='')
		{
			$img7 = $_FILES['img7']['name'];	
			$imgname7 = explode('.',$img7);	
			$count7 = count($imgname7)-1;
			$img7 = '7_'.time().'.'.$imgname7[$count7];
			$img7_1 ='7_'.time().'_1.'.$imgname7[$count7];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img7;
			$upload_file = $_FILES['img7']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img7;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img7_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img7='$img7_1' where id=$insert_id");
		}

		if($_FILES['img8']['name']!='')
		{
			$img8 = $_FILES['img8']['name'];	
			$imgname8 = explode('.',$img8);	
			$count8 = count($imgname8)-1;
			$img8 = '8_'.time().'.'.$imgname8[$count8];
			$img8_1 ='8_'.time().'_1.'.$imgname8[$count8];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img8;
			$upload_file = $_FILES['img8']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img8;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img8_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img8='$img8_1' where id=$insert_id");
		}

		if($_FILES['img9']['name']!='')
		{
			$img9 = $_FILES['img9']['name'];	
			$imgname9 = explode('.',$img9);	
			$count9 = count($imgname9)-1;
			$img9 = '9_'.time().'.'.$imgname9[$count9];
			$img9_1 ='9_'.time().'_1.'.$imgname9[$count9];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img9;
			$upload_file = $_FILES['img9']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img9;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img9_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img9='$img9_1' where id=$insert_id");
		}

		if($_FILES['img10']['name']!='')
		{
			$img10 = $_FILES['img10']['name'];	
			$imgname10 = explode('.',$img10);	
			$count10 = count($imgname10)-1;
			$img10 = '10_'.time().'.'.$imgname10[$count10];
			$img10_1 ='10_'.time().'_1.'.$imgname10[$count10];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img10;
			$upload_file = $_FILES['img10']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img10;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img10_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img10='$img10_1' where id=$insert_id");
		}

		if($_FILES['img11']['name']!='')
		{
			$img11 = $_FILES['img11']['name'];	
			$imgname11 = explode('.',$img11);	
			$count11 = count($imgname11)-1;
			$img11 = '11_'.time().'.'.$imgname11[$count11];
			$img11_1 ='11_'.time().'_1.'.$imgname11[$count11];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img11;
			$upload_file = $_FILES['img11']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img11;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img11_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img11='$img11_1' where id=$insert_id");
		}

		if($_FILES['img12']['name']!='')
		{
			$img12 = $_FILES['img12']['name'];	
			$imgname12 = explode('.',$img12);	
			$count12 = count($imgname12)-1;
			$img12 = '12_'.time().'.'.$imgname12[$count12];
			$img12_1 ='12_'.time().'_1.'.$imgname12[$count12];

			$img_file =$conf['fck_upload'] . "house/".$insert_id;
			$file_full = $img_file."/".$img12;
			$upload_file = $_FILES['img12']['tmp_name'];          
			move_uploaded_file($upload_file, $file_full);
			$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img12;
			$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img12_1;		
			new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略图
			mysql_query("update $TBL_HOUSE SET img12='$img12_1' where id=$insert_id");
		}

		MyNotice("出售房添加成功", 2, "cs.php");
		exit(0);

	}

	$sel4 = "select * from $TBL_HOU_CATE where parent_id=0 order by cate_order asc";   //導航
	$res4 =$db->query($sel4);
	while($rows = $db->fetch_array($res4))
	{
		$row4[]=$rows;		
	}

	$selfd = "select * from $TBL_STORE order by id asc"; //分店
	$resultfd = mysql_query($selfd);
	while($rowfd = mysql_fetch_array($resultfd))
	{
		$fd  =$fd."<option value=$rowfd[id]>$rowfd[name]</option>";
	}
	
	include_once("xuanxiang.php");

	//加载FCKeditor编辑器
    include("siteadmin/fckeditor/fckeditor.php");
  //中文
    $editor = new FCKeditor('tese');
    $editor -> BasePath   = "siteadmin/fckeditor/";
    $editor -> ToolbarSet = "Basic";
    $editor -> Width      = "70%";
    $editor -> Height     = "200";
    $edit = $editor->CreateHtml();

	$smarty->assign("mem_id",$_SESSION['mem_id']);
	$smarty->assign("edit",$edit);
	$smarty->assign("type",$_SESSION['type']);
	$smarty->assign("row4",$row4);	
	$smarty->assign("fd",$fd);	
	//@include('number.php');//验证码
	$smarty->display('add_cs.html');

?>